package com.yndsoft.jc.supplier.adapter;

import android.content.Context;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.yndsoft.jc.R;
import com.yndsoft.jc.supplier.model.CommentModel;
import com.yndsoft.jc.supplier.widget.recyclerview.RecyclerAdapter;
import com.yndsoft.jc.supplier.widget.recyclerview.RecyclerHolder;
import com.yndsoft.jc.supplier.widget.recyclerview.RecyclerListener;
import com.yndsoft.jc.widget.StarBar;

public class CommentAdapter extends RecyclerAdapter<CommentModel> implements RecyclerListener.OnClickListener<RecyclerHolder> {

    public CommentAdapter(Context context) {
        super(context, null, R.layout.item_comment);
    }

    @Override
    public void convert(RecyclerHolder holder, CommentModel model) {

        CommentModel.MemberBean member = model.getMember();
        if (member != null) {
            holder.setTvText(R.id.comment_name, member.getName() != null ? member.getName() : "");
            String img = member.getImg();
            if (img != null) {
                ImageView commentHead = holder.findViewById(R.id.comment_head);
                Glide.with(mContext).load(img).placeholder(R.mipmap.logo).into(commentHead);
            }
        }
        holder.setTvText(R.id.comment_time, model.getTime() != null ? model.getTime() : "");
        holder.setTvText(R.id.comment_content, model.getNote() != null ? model.getNote() : "");

        StarBar commentStar = holder.findViewById(R.id.comment_star);
        commentStar.setStarMark(model.getStar());
        commentStar.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                return true;
            }
        });
    }

    @Override
    public void onClick(View v, int position, RecyclerHolder holder) {

    }
}
